﻿using Renci.iRods.Common;

namespace Renci.iRods.Packets
{

    //#define StartupPack_PI "int irodsProt; int reconnFlag; int connectCnt; str proxyUser[NAME_LEN]; str proxyRcatZone[NAME_LEN]; str clientUser[NAME_LEN]; str clientRcatZone[NAME_LEN]; str relVersion[NAME_LEN]; str apiVersion[NAME_LEN]; str option[NAME_LEN];" 
    [PacketAttribute("StartupPack_PI")]
    internal class StartupPacket : Packet
    {
        //internal const string NAME = "StartupPack_PI";

        /// <summary>
        /// Gets or sets the protocol.
        /// </summary>
        /// <value>
        /// The protocol.
        /// </value>
        [PacketField("irodsProt", 0, DataTypes.Enum)]
        public PackingType PackingType { get; set; }

        /// <summary>
        /// Gets or sets the reconnect flag.
        /// </summary>
        /// <value>
        /// The reconnect flag.
        /// </value>
        [PacketField("reconnFlag", 1, DataTypes.Int)]
        public int ReconnectFlag { get; set; }

        /// <summary>
        /// Gets or sets the connect CNT.
        /// </summary>
        /// <value>
        /// The connect CNT.
        /// </value>
        [PacketField("connectCnt", 2, DataTypes.Int)]
        public int ConnectCounter { get; set; }

        /// <summary>
        /// Gets or sets the proxy username.
        /// </summary>
        /// <value>
        /// The proxy username.
        /// </value>
        [PacketField("proxyUser", 3, DataTypes.String, 64)]
        public string ProxyUsername { get; set; }

        /// <summary>
        /// Gets or sets the proxy rods zone.
        /// </summary>
        /// <value>
        /// The proxy rods zone.
        /// </value>
        [PacketField("proxyRcatZone", 4, DataTypes.String, 64)]
        public string ProxyRcatZone { get; set; }

        /// <summary>
        /// Gets or sets the client username.
        /// </summary>
        /// <value>
        /// The client username.
        /// </value>
        [PacketField("clientUser", 5, DataTypes.String, 64)]
        public string ClientUsername { get; set; }

        /// <summary>
        /// Gets or sets the client rods zone.
        /// </summary>
        /// <value>
        /// The client rods zone.
        /// </value>
        [PacketField("clientRcatZone", 6, DataTypes.String, 64)]
        public string ClientRcatZone { get; set; }

        /// <summary>
        /// Gets or sets the rel version.
        /// </summary>
        /// <value>
        /// The rel version.
        /// </value>
        [PacketField("relVersion", 7, DataTypes.String, 64)]
        public string RelVersion { get; set; }

        /// <summary>
        /// Gets or sets the API version.
        /// </summary>
        /// <value>
        /// The API version.
        /// </value>
        [PacketField("apiVersion", 8, DataTypes.String, 64)]
        public string ApiVersion { get; set; }

        /// <summary>
        /// Gets or sets the option.
        /// </summary>
        /// <value>
        /// The option.
        /// </value>
        [PacketField("option", 9, DataTypes.String, 64)]
        public string Option { get; set; }


        //public override byte[] PackAsBinary()
        //{
        //    throw new System.NotImplementedException();
        //}

        //public override byte[] PackAsXml()
        //{
        //    StringBuilder xml = new StringBuilder();
        //    xml.AppendFormat("<{0}>", StartupPacket.NAME);
        //    xml.AppendFormat("<irodsProt>{0}</irodsProt>", (int)this.PackingType);
        //    xml.AppendFormat("<reconnFlag>{0}</reconnFlag>", this.ReconnectFlag);
        //    xml.AppendFormat("<connectCnt>{0}</connectCnt>", this.ConnectCounter);
        //    xml.AppendFormat("<proxyUser>{0}</proxyUser>", this.ProxyUsername);
        //    xml.AppendFormat("<proxyRcatZone>{0}</proxyRcatZone>", this.ProxyRcatZone);
        //    xml.AppendFormat("<clientUser>{0}</clientUser>", this.ClientUsername);
        //    xml.AppendFormat("<clientRcatZone>{0}</clientRcatZone>", this.ClientRcatZone);
        //    xml.AppendFormat("<relVersion>{0}</relVersion>", this.RelVersion);
        //    xml.AppendFormat("<apiVersion>{0}</apiVersion>", this.ApiVersion);
        //    xml.AppendFormat("<option>{0}</option>", this.Option);
        //    xml.AppendFormat("</{0}>", StartupPacket.NAME);

        //    return Encoding.ASCII.GetBytes(xml.ToString());
        //}

        //public override void Unpack(byte[] data)
        //{
        //    throw new System.NotImplementedException();
        //}

        //public override void Unpack(XElement xml)
        //{
        //    if (!xml.Name.LocalName.Equals(StartupPacket.NAME))
        //        throw new InvalidOperationException(string.Format("'{0}' is expected", StartupPacket.NAME));

        //    this.PackingType = (PackingType)int.Parse(xml.Element("irodsProt").Value);
        //    this.ReconnectFlag = int.Parse(xml.Element("reconnFlag").Value);
        //    this.ConnectCounter = int.Parse(xml.Element("connectCnt").Value);
        //    this.ProxyUsername = xml.Element("proxyUser").Value;
        //    this.ProxyRcatZone = xml.Element("proxyRcatZone").Value;
        //    this.ClientUsername = xml.Element("clientUser").Value;
        //    this.ClientRcatZone = xml.Element("clientRcatZone").Value;
        //    this.RelVersion = xml.Element("relVersion").Value;
        //    this.ApiVersion= xml.Element("apiVersion").Value;
        //    this.Option = xml.Element("option").Value;
        //}
    }
}
